package faceService;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.qcloud.image.ImageClient;
import com.qcloud.image.common_utils.CommonFileUtils;
import com.qcloud.image.demo.Demo;
import com.qcloud.image.request.FaceIdentifyRequest;
import dto.SearchFaceDto;
import util.AppContast;

import java.util.logging.Level;
import java.util.logging.Logger;

import static com.qcloud.image.http.RequestBodyKey.BUCKET;

/**
 * Created by Administrator on 2017/9/28.
 */
public class SearchFace {

    public SearchFaceDto searchFace(String imgPath) {
        ImageClient imageClient = new ImageClient(AppContast.APP_ID, AppContast.SERCET_ID, AppContast.SERCET_KEY);
        String bucketName = BUCKET;

        String  faceIdentifyGroupId = "group1";

        String faceIdentifyName  = "";
        String faceIdentifyImage = "";
        try {
            faceIdentifyName = "test.jpg";
            faceIdentifyImage = CommonFileUtils.getFileContent(imgPath);
        } catch (Exception ex) {
            Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
        }

        FaceIdentifyRequest faceIdentifyReq = new FaceIdentifyRequest(bucketName, faceIdentifyGroupId, faceIdentifyName, faceIdentifyImage);
        String ret = imageClient.faceIdentify(faceIdentifyReq);

        System.out.println("face identify ret:" + ret);

        SearchFaceDto searchFaceDto = JSON.parseObject(ret, new TypeReference<SearchFaceDto>() {});


        return searchFaceDto;
    }
}
